package com.idea.web.common;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

import org.apache.commons.lang3.StringUtils;
import org.apache.log4j.Logger;
import org.springframework.core.convert.converter.Converter;

public class String2DateConverter implements Converter<String,Date> {

	private static final Logger logger = Logger.getLogger(String2DateConverter.class);
	
	@Override
	public Date convert(String source) {
		if(StringUtils.isEmpty(source.trim())){
			return null;
		}
		SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
		try {
			return dateFormat.parse(source);
		} catch (ParseException e) {
			logger.error(e.getMessage(),e);
			return null;
		}
	}

}
